import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutterapp/page/view/MealWidget.dart';
import 'package:flutterapp/utils/screen.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class OrderMealRecordPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _OrderMealRecordState();
  }
}

class _OrderMealRecordState extends State<OrderMealRecordPage> {
  int _itemCont = 10;
  RefreshController _refreshController =RefreshController(initialRefresh: false);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          leading: IconButton(
              icon: Image.asset(
                'assets/meal/images/ic_btn_back_white.png',
                width: 32,
                height: 32,
              ),
              iconSize: dpWidth(48),
              onPressed: () {
                Navigator.pop(context);
              }),
          centerTitle: true,
          title: Text(
            "订餐",
            style: TextStyle(color: Colors.white, fontSize: spFont(36)),
          ),
        ),
        body: SmartRefresher(
          enablePullDown: true,
          enablePullUp: true,
          onRefresh: onRefresh,
          onLoading: onLoad,
          controller: _refreshController,
          child: ListView.separated(
              itemCount: _itemCont,
              itemBuilder: (BuildContext context, int index) {
                return MealRecordItemWidget();
              },
              separatorBuilder: (BuildContext context, int position) {
                return Divider(
                    height: dpHeight(20),
                    color: Color.fromARGB(255, 245, 245, 245));
              }),
        ));
  }

  onRefresh(){
    Future.delayed(Duration(milliseconds: 1000)).then((e) {
      _refreshController.refreshCompleted();
      setState(() {
        _itemCont = 10;
      });
    });
  }

  onLoad(){
    Future.delayed(Duration(milliseconds: 1000)).then((e) {
      _refreshController.loadComplete();
      setState(() {
        _itemCont = _itemCont + 10;
      });
    });
  }
}
